﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CXJ.WindowsForms
{
    public partial class MainForm : Form
    {
        CXJ.Model.tbAdminEntity _Entity = new CXJ.Model.tbAdminEntity();
        BLL.tbAdmin _tbAdmin = new CXJ.BLL.tbAdmin();

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            _tbAdmin.SelectData(this.dataGridView1);
        }


        private void button_Insert_Click(object sender, EventArgs e)
        {
            _tbAdmin.InsertData(_Entity);
        }

        private void button_Update_Click(object sender, EventArgs e)
        {
            CXJ.Model.tbAdminEntity pEntity = null;
            if (dataGridView1.SelectedRows.Count > 0)
            {
                DataGridViewRow dr = dataGridView1.SelectedRows[0];

                pEntity = new CXJ.Model.tbAdminEntity
                {
                    iadmID = dr.Cells["iadmID"].Value.ToString(),
                    sUserName = dr.Cells["sUserName"].Value.ToString(),
                    sPassword = dr.Cells["sPassword"].Value.ToString(),
                    iPermission = dr.Cells["iPermission"].Value.ToString(),
                    dDateTime = DateTime.Now.ToString(),
                };
            }
            _tbAdmin.UpdateData(pEntity);
        }

        private void button_delete_Click(object sender, EventArgs e)
        {
            _tbAdmin.DeleteData(dataGridView1);
        }

        private void button_Select_Click(object sender, EventArgs e)
        {
            _tbAdmin.SelectDataWithCondition(dataGridView1);
        }
    }
}
